/**
 * Created by ${PRODUCT_NAME}.
 * User: skylerparr
 * Date: 12/27/10
 * Time: 6:53 PM
 * To change this template use File | Settings | File Templates.
 */
package com.thoughtorigin.data {
import com.thoughtorigin.loader.AbstractLoader;

import flash.utils.Dictionary;

public class SimpleDataCache implements DataCache {

    private var _assetDic: Dictionary;

    public function SimpleDataCache() {
        init();
    }

    protected function init(): void {
        _assetDic = new Dictionary(true);
    }

    public function isAssetCached(url:String):Boolean {
        return _assetDic[url];
    }

    public function cacheAsset(absLoader:AbstractLoader):void {
        if(isAssetCached(absLoader.url)) return;
        _assetDic[absLoader.url] = absLoader.content;
    }

    /**
     * caveat... the returned data "can" be mutated.
     * So be careful what you do.
     * @param url
     * @return
     */
    public function getAsset(url:String):Object {
        return _assetDic[url];
    }

    public function deleteAsset(url:String):void {
        delete _assetDic[url];
    }
}
}
